package com.freewater.springboot.demo.aop.introduction;

import java.math.BigInteger;

public class DefaultUsageTracked implements UsageTracked {

    private int usageCount;

    @Override
    public void increaseUseCount(Object service) {
        this.usageCount = this.usageCount + 1;
        System.out.printf("this: %s, count map: %s%n",
                getIdentityHashCode(this),
                this.usageCount);
    }

    private String getIdentityHashCode(Object obj) {
        int hashCode = System.identityHashCode(obj);
        return "0x" + BigInteger.valueOf(hashCode).toString(16);
    }
}
